package com.raincat.tools.multimediapickertools.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.raincat.tools.R;
import com.raincat.tools.multimediapickertools.PictureActivity;

import java.io.Serializable;
import java.util.List;

/**
 * <pre>
 *     author : RainCat
 *     org    : Shenzhen JingYu Network Technology Co., Ltd.
 *     e-mail : nining377@gmail.com
 *     time   : 2019/02/15
 *     desc   : 多媒体配置
 *     version: 1.0
 * </pre>
 */

public class PickerConfig implements Serializable {
    int themeId = R.style.picker_default_style;
    /**
     * 0、图片选择，1、图片裁剪，2、混合选择，3、视频选择
     */
    int mode = 0;
    /**
     * 裁剪输出大小，默认300
     */
    int outputX = 300;
    int outputY = 300;

    /**
     * 图片或视频默认最大尺寸
     */
    int imageMaxSize = 10 * 1024 * 1024;
    int videoMaxSize = 100 * 1024 * 1024;
    /**
     * 视频默认最大时长
     */
    long videoMaxDuration = 10 * 60 * 1000;
    /**
     * 图片选择数量，默认为1
     */
    int maxCount = 1;
    /**
     * 是否显示拍照
     */
    boolean showCameraOption = true;
    /**
     * 是否显示原图
     */
    boolean showOriginalOption = false;
    /**
     * 是否显示GIF图
     */
    boolean showGif = true;
    /**
     * 黑色状态栏
     */
    boolean blackStatusBar = false;

    List<MultiMediaItem> existingMultiMediaList;

    /**
     * 设置主题
     *
     * @param themeId 主题Id
     */
    public PickerConfig setThemeId(int themeId) {
        this.themeId = themeId;
        return this;
    }

    /**
     * 图片获取
     */
    public PickerConfig asImagePick() {
        mode = 0;
        return this;
    }

    /**
     * 图片裁切
     */
    public PickerConfig asImageCrop() {
        mode = 1;
        return this;
    }

    /**
     * 图片+视频获取
     */
    public PickerConfig asMixPick() {
        mode = 2;
        return this;
    }

    /**
     * 视频获取
     */
    public PickerConfig asVideoPick() {
        mode = 3;
        return this;
    }

    /**
     * 可选的图片最大个数
     */
    public PickerConfig withMaxCount(int maxCount) {
        this.maxCount = maxCount;
        return this;
    }

    /**
     * 可选的单个图片或视频的最大容量
     */
    public PickerConfig withMaxSize(int imageMaxSize, int videoMaxSize) {
        this.videoMaxSize = videoMaxSize;
        this.imageMaxSize = imageMaxSize;
        return this;
    }

    /**
     * 可选的单个视频的最大时长
     */
    public PickerConfig withMaxDuration(long duration) {
        this.videoMaxDuration = duration;
        return this;
    }

    /**
     * 若在选择之前已有部分图片被选择
     */
    public PickerConfig withExistingMultiMediaList(List<MultiMediaItem> multiMediaItemList) {
        this.existingMultiMediaList = multiMediaItemList;
        return this;
    }

    public PickerConfig showGif(boolean isShowGif) {
        this.showGif = isShowGif;
        return this;
    }

    public PickerConfig showCameraOption(boolean isShowCameraOption) {
        showCameraOption = isShowCameraOption;
        return this;
    }

    public PickerConfig showOriginalOption(boolean isShowOriginalOption) {
        showOriginalOption = isShowOriginalOption;
        return this;
    }

    public PickerConfig withCropOutputSize(int width, int height) {
        outputX = width;
        outputY = height;
        return this;
    }

    public PickerConfig withBlackStatusBar() {
        blackStatusBar = true;
        return this;
    }

    public void start(Context context, PickerListener pickerListener) {
        PickerListenerManager.getInstance().setPickerListenerListener(pickerListener);
        MultiMediaController.initController(this);

        Intent intent = new Intent(context, PictureActivity.class);
        intent.putExtra("Config", this);
        context.startActivity(intent);
        ((Activity) context).overridePendingTransition(R.anim.push_bottom_in, 0);
    }

    /**
     * 初始化
     */
    public static void reset() {
        MultiMediaController.reset();
        MultiMediaHelper.onDestroy();
    }

    /**
     * 清除缓存，最好等上传成功后调用以防未上传完毕导致上传不成功
     */
    public static void cleanCache(Context context) {
        ImageCacheUtils imageCacheUtils = new ImageCacheUtils(context);
        imageCacheUtils.deleteDir();
    }
}
